package cn.avalon.order.listener;

import cn.avalon.order.domain.OrderPetAcquisition;
import cn.avalon.order.mapper.OrderPetAcquisitionMapper;
import cn.avalon.order.service.impl.OrderPetAcquisitionServiceImpl;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @description: 延迟同步
 * @author: Avalon
 * @date: 2022年09月15日 ： 21:29
 * @version: ver1.0
 * @email 709785494@qq.com
 */
@Component
@RocketMQMessageListener(topic = "delay-topic",consumerGroup = "consumer-group")
public class DelayConsumer implements RocketMQListener<String> {

    @Autowired
    private OrderPetAcquisitionMapper orderPetAcquisitionMapper;

    @Autowired
    private OrderPetAcquisitionServiceImpl orderPetAcquisitionService;

    @Override
    public void onMessage(String s) {
        OrderPetAcquisition order = orderPetAcquisitionMapper.findByMsgId(Long.valueOf(s));
        if (order != null && order.getState().equals(0)) {
            orderPetAcquisitionService.cancel(order.getId());
        }
    }
}
